#!/bin/bash

############################################################################
#
# 远程执行该脚本，请在命令行中直接执行以下命令：
#
#   curl -sSL https://gitee.com/tay3223/biubiubiu/raw/master/centos7-install-docker.sh | /bin/bash
#
#
############################################################################


# 卸载原来旧的docker
#systemctl disable docker && systemctl stop docker
#yum remove docker \
#    docker-client \
#    docker-client-latest \
#    docker-common \
#    docker-latest \
#    docker-latest-logrotate \
#    docker-logrotate \
#    docker-engine


#参考文档：https://help.aliyun.com/zh/ecs/use-cases/install-and-use-docker-on-a-linux-ecs-instance?spm=a2c4g.11186623.help-menu-25365.d_5_3_5.e57d7d92xtPLMs#9b082cb332wnq
#卸载旧版的docker
systemctl disable docker && systemctl stop docker
yum -y remove \
  docker-ce \
  containerd.io \
  docker-ce-rootless-extras \
  docker-buildx-plugin \
  docker-ce-cli \
  docker-compose-plugin


# 安装依赖
yum install -y yum-utils \
    device-mapper-persistent-data \
    epel-release \
    python-pip \
    lvm2 \
    git


# 添加docker源
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo


# 安装docker
yum -y install \
  docker-ce \
  docker-ce-cli \
  containerd.io \
  docker-buildx-plugin \
  docker-compose-plugin


# 安装docker-compose
#wget https://osoc.oss-cn-shanghai.aliyuncs.com/bao/docker-compose/v2.2.2/docker-compose-linux-x86_64 -O /usr/local/bin/docker-compose
#wget https://file.taycc.com/d/bao/docker-compose/v2.2.2/docker-compose-linux-x86_64 -O /usr/local/bin/docker-compose
wget https://file.taycc.com/d/bao/docker-compose/v2.23.3/docker-compose-linux-x86_64 -O /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version


# 启动 && 开机启动
systemctl enable docker
systemctl start docker


# 添加镜像加速源
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<EOF
{
    "registry-mirrors": [
        "https://dockerproxy.com",
        "https://docker.nju.edu.cn",
        "https://docker.mirrors.ustc.edu.cn",
        "https://ccr.ccs.tencentyun.com",
        "https://docker.m.daocloud.io",
        "https://hub-mirror.c.163.com",
        "https://mirror.baidubce.com"
    ],
    "exec-opts": [
        "native.cgroupdriver=systemd"
    ],
    "bip": "192.168.99.1/24",
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "100m",
        "max-file": "10"
    },
   "default-address-pools": [
    {
      "base": "192.168.100.0/24",
      "size": 26
    }
  ]
}
EOF


systemctl daemon-reload
systemctl restart docker


cat <<Tay

====================================
1.已设置为开机启动（√ ）
2.已经启动docker服务（√ ）
3.相关命令：
    systemctl restart docker
    systemctl start docker
    systemctl enable docker
====================================

Tay

VERSION=$(docker --version)
echo -e "\n当前docker版本为\n\n：${VERSION} \n"
